import random
import time

import win32api, win32con;

class Move:
    hwnd = -1,
    location = {
        "x":0,
        "y":0};
    def __init__(self, hwnd):
        self.hwnd = hwnd;
    def up(self):
        win32api.PostMessage(self.hwnd, win32con.WM_KEYDOWN, 87,0)
        rightTime = random.randrange(60, 61) / 100.0
        sleepTime = random.randrange(24, 25) / 100.0
        time.sleep(sleepTime)
        upTime = 0.3  + random.randrange(23, 24) / 100.0
        win32api.PostMessage(self.hwnd, win32con.WM_KEYDOWN, 68,0)
        time.sleep(rightTime)
        win32api.PostMessage(self.hwnd, win32con.WM_KEYUP, 68,0)
        self.location['x'] -= rightTime;
        time.sleep(upTime)
        self.location['y'] -= sleepTime + upTime + rightTime;
        time.sleep(upTime)
        win32api.PostMessage(self.hwnd, win32con.WM_KEYUP, 87,0)

    def down(self):
        win32api.PostMessage(self.hwnd, win32con.WM_KEYDOWN, 83,0)
        rightTime = random.randrange(60, 65) / 100.0
        sleepTime = random.randrange(20, 25) / 100.0
        time.sleep(sleepTime)
        upTime = 0.3  + random.randrange(20, 25) / 100.0
        win32api.PostMessage(self.hwnd, win32con.WM_KEYDOWN, 65,0)
        time.sleep(rightTime)
        win32api.PostMessage(self.hwnd, win32con.WM_KEYUP, 65,0)
        self.location['x'] -= rightTime;
        time.sleep(upTime)
        self.location['y'] -= sleepTime + upTime + rightTime;
        time.sleep(upTime)
        win32api.PostMessage(self.hwnd, win32con.WM_KEYUP, 83,0)

    def right(self):
        rightTime = (1 - self.location['x']) + random.randrange(30, 100) / 100.0
        win32api.PostMessage(self.hwnd, win32con.WM_KEYDOWN, 68,0)
        upTime = 1 + random.randrange(20, 100) / 100.0
        self.location['x'] -= rightTime;
        time.sleep(rightTime)
        win32api.PostMessage(self.hwnd, win32con.WM_KEYUP, 68,0)

